<template>
    <aside class="sidebar">
      <h3>侧边栏</h3>
      <p>这里可以放置广告、链接或其他内容。</p>
      <div class="ad" v-if="showAd">广告位</div>
    </aside>
  </template>
  
  <script setup>
  import { ref, onMounted, onUnmounted } from 'vue'
  
  const showAd = ref(true)
  
  // 响应式处理 - 在小屏幕上隐藏广告
  const handleResize = () => {
    showAd.value = window.innerWidth > 768
  }
  
  onMounted(() => {
    handleResize()
    window.addEventListener('resize', handleResize)
  })
  
  onUnmounted(() => {
    window.removeEventListener('resize', handleResize)
  })
  </script>
  
  <style scoped>
  .sidebar {
    background: #f1f1f1;
    padding: 1.5rem;
    border-radius: 8px;
  }
  
  .ad {
    background: #3498db;
    color: white;
    padding: 1rem;
    text-align: center;
    margin-top: 1rem;
    border-radius: 8px;
  }
  
  @media (max-width: 768px) {
    .sidebar {
      margin-top: 2rem;
    }
  }
  </style>